package top.zkh.login;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.JOptionPane;

import com.java1234.dao.animalDao;
import com.java1234.model.animal;
import com.java1234.util.DbUtil;
import com.java1234.util.StringUtil;

public class modifyServlet extends HttpServlet{
	private DbUtil dbUtil = new DbUtil();
	private animalDao animaldao=new animalDao();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		req.setCharacterEncoding ("utf-8");
		resp.setContentType("text/html;carset=utf-8");
		Connection con =null;
		PreparedStatement ps =null;	
		String id = req.getParameter("ID");
		String name = req.getParameter("animalName");
		String type = req.getParameter("animalType");
		String price = req.getParameter("Price");
		String txt = req.getParameter("Txt");
		if(StringUtil.isEmpty(name)) {
			System.out.println("失败");
			req.getRequestDispatcher("views/error.jsp").forward(req, resp);
			return;
		}
		animal animal1 = new animal(id,name,type,price,txt);
		try {
			con = dbUtil.getCon();
			int count=animaldao.update(con, animal1);
			if(count==1)
			{
				System.out.println("添加成功");
				req.getRequestDispatcher("modify.jsp").forward(req, resp);
			}else {
				System.out.println("添加失败");
				req.getRequestDispatcher("error.jsp").forward(req, resp);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doGet(req, resp);
	}

}